package com.hdu.point_offer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class lcr150 {


    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {
        public List<List<Integer>> decorateRecord(TreeNode root) {
            List<List<Integer>> ans = new ArrayList<>();
            if (root == null) return ans;
            Queue<TreeNode> q = new LinkedList<>();
            q.offer(root);
            boolean flag = true;
            while (!q.isEmpty()) {
                int size = q.size();
                List<Integer> tmp = new ArrayList<>();
                for (int i = 0; i < size; i++) {
                    TreeNode node = q.poll();
                    if (flag) {
                        tmp.add(node.val);
                    }
                    else
                    {
                        tmp.add(0, node.val);
                    }
                    if (node.left != null) q.offer(node.left);
                    if (node.right != null) q.offer(node.right);
                }
                flag = !flag;
                ans.add(tmp);
            }
            return ans;
        }
    }
}
